#the following script allows one to replicate all monthly analyses pertaining to Cabo Delgado
#it uses the following files: monthly_cyclone_ts.dta and pests.r

#load necessary libraries
library(foreign)
library(MASS)

#source in pests r code
source("C:/Users/bagoz/Dropbox/Conflict Projects/Cabo Delgado/pests.r")

#set random number seed
set.seed(10)

#read-in dataset
cyclonedata <- read.dta(file = "monthly_cyclone_ts.dta")
attach(cyclonedata)

##############################
###Table A.10, Final Column###
##############################

#baseline specification
Cyclone.small <- Parp(moz_rebcit_acled ~ fullcyclone, p=2)
print(Cyclone.small)

###############
###Table A.9###
###############

#small specification
Cyclone.small <- Parp(moz_rebcit_acled ~ fullcyclone+moz_govreb_acled+lagmoz_govreb_acled, p=2)
print(Cyclone.small)

#medium specification
Cyclone.medium <- Parp(moz_rebcit_acled ~ fullcyclone+moz_govreb_acled+lagmoz_govreb_acled+moz_rebgov_acled+lagmoz_rebgov_acled+lag2moz_rebgov_acled, p=2)
print(Cyclone.medium)

#large specification
Cyclone.large <- Parp(moz_rebcit_acled ~ fullcyclone+moz_govreb_acled+lagmoz_govreb_acled+moz_rebgov_acled+lagmoz_rebgov_acled+lag2moz_rebgov_acled+moz_govcit_acled+lagmoz_govcit_acled, p=2)
print(Cyclone.large)

#extra large specification
Cyclone.xl <- Parp(moz_rebcit_acled ~ fullcyclone+moz_govreb_acled+lagmoz_govreb_acled+moz_rebgov_acled+lagmoz_rebgov_acled+lag2moz_rebgov_acled+moz_govcit_acled+lagmoz_govcit_acled+moz_ncd+lagmoz_ncd+lag2moz_ncd+russian, p=2)
print(Cyclone.xl)

#############
###Figures###
#############

#Figure 1
barplot(moz_rebcit_acled, horiz=FALSE,cex.names=.75,ylim=c(0,30),ylab="Insurgent Violence Against Civilians",xlab="Monthly Observations: March 2018 - April 2020",names.arg=c("Mar","Apr","May","Jun","July","Aug","Sep","Oct","Nov","Dec","Jan","Feb","Mar","Apr","May","Jun","July","Aug","Sep","Oct","Nov","Dec","Jan","Feb","Mar","Apr"))
abline(v=15,col="red",lwd=2)
abline(v=16,col="blue",lwd=2)
text(11.5,28,"Cyclone Idai",cex=.85,col="red")
text(20.5,28,"Cyclone Kenneth",cex=.85,col="blue")
box()

